﻿using System;
using UnityEngine;

namespace UnityStandardAssets.ImageEffects
{
	// Token: 0x020004A7 RID: 1191
	[ExecuteInEditMode]
	[RequireComponent(typeof(Camera))]
	[AddComponentMenu("Image Effects/Edge Detection/Edge Detection")]
	public class EdgeDetection : PostEffectsBase
	{
		// Token: 0x060018A5 RID: 6309 RVA: 0x0006E7F4 File Offset: 0x0006CBF4
		public override bool CheckResources()
		{
			base.CheckSupport(true);
			this.edgeDetectMaterial = base.CheckShaderAndCreateMaterial(this.edgeDetectShader, this.edgeDetectMaterial);
			if (this.mode != this.oldMode)
			{
				this.SetCameraFlag();
			}
			this.oldMode = this.mode;
			if (!this.isSupported)
			{
				base.ReportAutoDisable();
			}
			return this.isSupported;
		}

		// Token: 0x060018A6 RID: 6310 RVA: 0x0006E85B File Offset: 0x0006CC5B
		private new void Start()
		{
			this.oldMode = this.mode;
		}

		// Token: 0x060018A7 RID: 6311 RVA: 0x0006E86C File Offset: 0x0006CC6C
		private void SetCameraFlag()
		{
			if (this.mode == EdgeDetection.EdgeDetectMode.SobelDepth || this.mode == EdgeDetection.EdgeDetectMode.SobelDepthThin)
			{
				base.GetComponent<Camera>().depthTextureMode |= DepthTextureMode.Depth;
			}
			else if (this.mode == EdgeDetection.EdgeDetectMode.TriangleDepthNormals || this.mode == EdgeDetection.EdgeDetectMode.RobertsCrossDepthNormals)
			{
				base.GetComponent<Camera>().depthTextureMode |= DepthTextureMode.DepthNormals;
			}
		}

		// Token: 0x060018A8 RID: 6312 RVA: 0x0006E8D3 File Offset: 0x0006CCD3
		private void OnEnable()
		{
			this.SetCameraFlag();
		}

		// Token: 0x060018A9 RID: 6313 RVA: 0x0006E8DC File Offset: 0x0006CCDC
		[ImageEffectOpaque]
		private void OnRenderImage(RenderTexture source, RenderTexture destination)
		{
			if (!this.CheckResources())
			{
				Graphics.Blit(source, destination);
				return;
			}
			Vector2 vector = new Vector2(this.sensitivityDepth, this.sensitivityNormals);
			this.edgeDetectMaterial.SetVector("_Sensitivity", new Vector4(vector.x, vector.y, 1f, vector.y));
			this.edgeDetectMaterial.SetFloat("_BgFade", this.edgesOnly);
			this.edgeDetectMaterial.SetFloat("_SampleDistance", this.sampleDist);
			this.edgeDetectMaterial.SetVector("_BgColor", this.edgesOnlyBgColor);
			this.edgeDetectMaterial.SetFloat("_Exponent", this.edgeExp);
			this.edgeDetectMaterial.SetFloat("_Threshold", this.lumThreshold);
			Graphics.Blit(source, destination, this.edgeDetectMaterial, (int)this.mode);
		}

		// Token: 0x04000F1F RID: 3871
		public EdgeDetection.EdgeDetectMode mode = EdgeDetection.EdgeDetectMode.SobelDepthThin;

		// Token: 0x04000F20 RID: 3872
		public float sensitivityDepth = 1f;

		// Token: 0x04000F21 RID: 3873
		public float sensitivityNormals = 1f;

		// Token: 0x04000F22 RID: 3874
		public float lumThreshold = 0.2f;

		// Token: 0x04000F23 RID: 3875
		public float edgeExp = 1f;

		// Token: 0x04000F24 RID: 3876
		public float sampleDist = 1f;

		// Token: 0x04000F25 RID: 3877
		public float edgesOnly;

		// Token: 0x04000F26 RID: 3878
		public Color edgesOnlyBgColor = Color.white;

		// Token: 0x04000F27 RID: 3879
		public Shader edgeDetectShader;

		// Token: 0x04000F28 RID: 3880
		private Material edgeDetectMaterial;

		// Token: 0x04000F29 RID: 3881
		private EdgeDetection.EdgeDetectMode oldMode = EdgeDetection.EdgeDetectMode.SobelDepthThin;

		// Token: 0x020004A8 RID: 1192
		public enum EdgeDetectMode
		{
			// Token: 0x04000F2B RID: 3883
			TriangleDepthNormals,
			// Token: 0x04000F2C RID: 3884
			RobertsCrossDepthNormals,
			// Token: 0x04000F2D RID: 3885
			SobelDepth,
			// Token: 0x04000F2E RID: 3886
			SobelDepthThin,
			// Token: 0x04000F2F RID: 3887
			TriangleLuminance
		}
	}
}
